package com.zyf.lj.service.impl;

import com.zyf.lj.entity.Application;
import com.zyf.lj.mapper.ApplicationMapper;
import com.zyf.lj.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 报名申请服务实现类
 */
@Service
public class ApplicationServiceImpl implements ApplicationService {
    
    @Autowired
    private ApplicationMapper applicationMapper;
    
    @Override
    @Transactional
    public boolean submitApplication(Application application) {
        // 设置初始状态
        application.setStatus(0); // 待处理状态
        application.setIsDeleted(0); // 未删除
        return applicationMapper.insert(application) > 0;
    }
    
    @Override
    public Application getApplicationById(Integer id) {
        return applicationMapper.selectById(id);
    }
    
    @Override
    public List<Application> getAllApplications() {
        return applicationMapper.selectAll();
    }
    
    @Override
    public List<Application> getApplicationsByStatus(Integer status) {
        return applicationMapper.selectByStatus(status);
    }
    
    @Override
    public List<Application> getApplicationsByIdCard(String idCard) {
        return applicationMapper.selectByIdCard(idCard);
    }
    
    @Override
    public List<Application> getApplicationsByPhone(String phone) {
        return applicationMapper.selectByPhone(phone);
    }
    
    @Override
    public List<Application> getApplicationsByCollegeId(Integer collegeId) {
        return applicationMapper.selectByCollegeId(collegeId);
    }
    
    @Override
    public List<Application> getApplicationsByMajorId(Integer majorId) {
        return applicationMapper.selectByMajorId(majorId);
    }
    
    @Override
    @Transactional
    public boolean updateApplication(Application application) {
        return applicationMapper.update(application) > 0;
    }
    
    @Override
    @Transactional
    public boolean updateApplicationStatus(Integer id, Integer status, String handler, String result) {
        return applicationMapper.updateStatus(id, status, handler, result) > 0;
    }
    
    @Override
    @Transactional
    public boolean deleteApplication(Integer id) {
        return applicationMapper.deleteById(id) > 0;
    }
} 